package cc.vv.btpartyjob.jnimodule.adapter

import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.view.ViewGroup
import cc.vv.baselibrary.util.LKLogUtil

/**
 * viewPager适配器
 * Created by Chen.qi on 2018/10/27.
 */
class JniViewPageAdapter : FragmentPagerAdapter {
    /**
     * Fragment数据集
     */
    private var mFragments: ArrayList<Fragment>? = null

    private var mTitles: ArrayList<String>? = null

    constructor(fm: FragmentManager, mFragments: ArrayList<Fragment>, mTitles: ArrayList<String>) : super(fm) {
        this.mFragments = mFragments
        this.mTitles = mTitles
    }

    constructor(fm: FragmentManager, mFragments: ArrayList<Fragment>) : super(fm) {
        this.mFragments = mFragments
    }

    override fun getItem(position: Int): Fragment {
        return mFragments!![position]
    }

    override fun getCount(): Int {
        return mFragments!!.size
    }

    override fun finishUpdate(container: ViewGroup?) {
        container!!.invalidate()
        super.finishUpdate(container)
    }

    override fun getPageTitle(position: Int): CharSequence {
        var title: String
        try {
            title = mTitles!![position]
        } catch (e: Exception) {
            LKLogUtil.e(e.message, e)
            title = ""
        }
        return title
    }
}